export default {
  getTable(list) {
    const result = []
    const ospan = []
    const kspan = []
    for (let i = 0; i < list.length; i++) {
      const ostart = result.length
      let m = 0
      if (list[i].list.length === 0) {
        result.push({
          'Objectives': list[i].name,
          'OScore': list[i].weight,
          'KeyResults': '',
          'KScore': '',
          'Capability': ''
        })
        m++
      }
      for (let j = 0; j < list[i].list.length; j++) {
        const kstart = result.length
        let n = 0
        if (list[i].list[j].list.length === 0) {
          result.push({
            'Objectives': list[i].name,
            'OScore': list[i].weight,
            'KeyResults': list[i].list[j].name,
            'KScore': list[i].list[j].weight,
            'Capability': ''
          })
          m++
          n++
        }
        for (let k = 0; k < list[i].list[j].list.length; k++) {
          result.push({
            'Objectives': list[i].name,
            'OScore': list[i].weight,
            'KeyResults': list[i].list[j].name,
            'KScore': list[i].list[j].weight,
            'Capability': list[i].list[j].list[k].name
          })
          m++
          n++
        }
        kspan.push({
          index: kstart,
          span: n
        })
      }
      ospan.push({
        index: ostart,
        span: m
      })
    }
    this.merge.ospan = ospan
    this.merge.kspan = kspan
    return result
  },
  objectSpanMethod({ row, column, rowIndex, columnIndex }) {
    if (columnIndex === 0 || columnIndex === 1) {
      for (let i = 0; i < this.merge.ospan.length; i++) {
        if (rowIndex === this.merge.ospan[i].index) {
          return [this.merge.ospan[i].span, 1]
        }
      }
      return [0, 0]
    }
    if (columnIndex === 2 || columnIndex === 3) {
      for (let i = 0; i < this.merge.kspan.length; i++) {
        if (rowIndex === this.merge.kspan[i].index) {
          return [this.merge.kspan[i].span, 1]
        }
      }
      return [0, 0]
    }
    return [1, 1]
  }
}
